/*
 * @Author: szx
 * @Date: 2022-04-27 14:39:34
 * @LastEditTime: 2022-04-27 14:49:42
 * @Description:
 * @FilePath: \leetcode\800-899\864\864.js
 */
/**
 * @param {number} n
 * @return {number}
 */
var binaryGap = function (n) {
    let index = -1,
        res = 0;
    for (let i = 0; n != 0; i++) {
        if (1 & n) {
            if (index != -1) res = Math.max(res, i - index);
            index = i;
        }
        n >>= 1;
    }
    return res;
};
